do "E:\yungyu\lottery_baby\do\set_environment.do"

clear
set more off

use "$wdata\project_lottery_fertility_b3a6_first_5k.dta", clear
drop if prize10M > 5

gen resident_urban = resident_t == 1 | resident_m == 1
gen female = pers_gender == 2
gen pers_labor = pers_earnings > 0

recode pers_real_prize_aftertax . = 0

forv i = 0(1)3{
	
	gen v1 = .
	replace v1 = pers_real_prize_aftertax if norm == -`i' & future == 0
	replace v1 = pers_real_prize_aftertax if norm == -`i' + 7 & future == 1
	egen pre`i'prize = mean(v1), by(houseid)
	drop v1
	recode pre`i'prize . = 0
}
gen totprize = pre1prize + pre2prize + pre3prize

foreach z in earnings income asset liquidasset saving{
	replace pers_`z' = pers_`z' / 10000 //10M
}

keep if norm == -1

gen prize1K = prize10M * 10000

gen anyredeem = tot_redeem_lotto > 0 | tot_redeem_receipt > 0
gen tot_redeem = tot_redeem_lotto + tot_redeem_receipt


cap rm "$table/temp/TabC2.txt"
cap rm "$table/temp/TabC2.xls"

reg prize1K resident_urban female married pers_labor pers_earnings pers_income pers_asset pers_liquidasset pers_saving totbaby if current == 1
outreg2 using "$table/temp/TabC2.xls" , append bd(3) sd(3) nocon ctitle(Current)
reg prize1K resident_urban female married pers_labor pers_earnings pers_income pers_asset pers_liquidasset pers_saving totbaby if current == 0
outreg2 using "$table/temp/TabC2.xls" , append bd(3) sd(3) nocon ctitle(Future)

import delimited using "$table/temp/TabC2.txt", clear
export excel "$table/Tables.xlsx", sheet("TabC2") sheetreplace 
